//
//  SettingViewController.m
//  tryshopping.boss
//
//  Created by Mr.Lee on 2016/12/13.
//  Copyright © 2016年 Reabam. All rights reserved.
//

#import "SettingViewController.h"
#import "LoginViewController.h"     // 登录
#import "AboutUsViewController.h"   // 关于我们

@interface SettingViewController ()
// tableView
@property (weak, nonatomic) IBOutlet UITableView *tableV;
// 退出登录按钮
@property (weak, nonatomic) IBOutlet UIButton *loginOutBtn;
@end

@implementation SettingViewController
{
    
    NSArray *array;
    UILabel*CFBundleVersion;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置导航条title字体大小
    self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:17]};
    self.title = @"设置";
    
//    [self.loginOutBtn setTitleColor:[UIColor colorWithHexString:@"ff3300"] forState:UIControlStateNormal];
 
    [self setUpTableView];
    
}

- (void)setUpTableView{
    array = @[@"当前版本"];
    self.tableV.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
    self.tableV.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.tableV.backgroundColor = zuiqianhuiColor;
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
}


#pragma mark -- tableViewDelegate/Datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.textColor=[UIColor colorWithHexString:@"333333"];
    cell.textLabel.font=[UIFont systemFontOfSize:17];
    cell.textLabel.text = [array objectAtIndex:indexPath.row];
//    if (indexPath.row==0) {
//        
//        UILabel *lineLabel11=[[UILabel alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, 0.5)];
//        lineLabel11.backgroundColor=qianhuiColor;
//        [cell.contentView addSubview:lineLabel11];
//        
//        
//        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(10, 50-0.35, ScreenWidth-20, 0.3)];
//        lineLabel1.backgroundColor=qianhuiColor;
//        [cell.contentView addSubview:lineLabel1];
//        
//        
//        UIButton*jiantou = [[UIButton alloc]init];
//        jiantou.frame = CGRectMake(ScreenWidth-13-15,(50-13)*0.5, 13, 13);
//        jiantou.userInteractionEnabled=NO;
//        [jiantou setImage:[UIImage imageNamed:@"arrow_right"] forState:UIControlStateNormal];
//        [cell.contentView addSubview:jiantou];
//        
//    }else{
    
    UIView *lineLabel0=[[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.5)];
    lineLabel0.backgroundColor=qianhuiColor;
    [cell.contentView addSubview:lineLabel0];
    
    
    UIView *lineLabel1=[[UIView alloc] initWithFrame:CGRectMake(0, 50-0.5, ScreenWidth, 0.5)];
    lineLabel1.backgroundColor=qianhuiColor;
    [cell.contentView addSubview:lineLabel1];
    
    [CFBundleVersion removeFromSuperview];
    CFBundleVersion=[[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth-170-15, 0, 170, 50)];
    CFBundleVersion.font=[UIFont systemFontOfSize:17.0];
    CFBundleVersion.textColor=zhonghuiColor;
    CFBundleVersion .textAlignment=NSTextAlignmentRight;
    [cell.contentView addSubview:CFBundleVersion];
    
//        UIButton*jiantou = [[UIButton alloc]init];
//        jiantou.frame = CGRectMake(ScreenWidth-13-15,(50-13)*0.5, 13, 13);
//        jiantou.userInteractionEnabled=NO;
//        [jiantou setImage:[UIImage imageNamed:@"arrow_right"] forState:UIControlStateNormal];
//        [cell.contentView addSubview:jiantou];
    
    // CFBundleShortVersionString   CFBundleVersion
    NSString *build = [NSString stringWithFormat:@"v%@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]];

    NSString *getVersion = [NSString stringWithFormat:@"v%@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
    CFBundleVersion.text = build;
//
//    }
    
    
    return cell;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    UITableViewCell *cell =(UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
//    if ([cell.textLabel.text isEqualToString:@"关于我们"]) {
//        AboutUsViewController *aboutUsVC=[[AboutUsViewController alloc]init];
//        aboutUsVC.view.backgroundColor = [UIColor whiteColor];
//        [self.navigationController pushViewController:aboutUsVC animated:YES];
//        
//    }else {
//
//    }
    
}

#pragma mark -- 退出登录
- (IBAction)logingOutBtnClick:(UIButton *)sender {
        
    UIAlertView* alts = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"是否确认注销？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
    [alts show];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        
    } else{
        
        NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
        NSString* tokenId = [user1 objectForKey:@"tokenId"];
        NSMutableDictionary *params = [NSMutableDictionary new];
        [params setValue:tokenId forKey:@"tokenId"];
        [HttpRequest requestData1:@"Common/LoginOut" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [MBProgressHUD hideProgressHUDInternal:self.view];
                    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                    [user setObject:@"out" forKey:@"tokenId"];
                    [user synchronize];
                    LoginViewController *loginVC=[[LoginViewController alloc]init];
                    [self.navigationController pushViewController:loginVC animated:YES];
                }else{
                    
                    [MBProgressHUD hideProgressHUDInternal:self.view];
                    NSString *subStr = [severDataDict.dataDict objectForKey:@"ResultString"];
                    [MBProgressHUD showTextHudSub:subStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        LoginViewController *loginVC = [[LoginViewController alloc] init];
                        [self.navigationController pushViewController:loginVC animated:YES];
                    }
                }
            } else {
                
                [MBProgressHUD hideProgressHUDInternal:self.view];
                NSString *subStr = [severDataDict.dataDict objectForKey:@"ResultString"];
                [MBProgressHUD showTextHudSub:subStr view:self.view];
            }
            
        }];

    }
}

 
 @end
